import axios from './http';
import { HttpResponse } from '../types/HttpResponse';

interface Url {
  [key: string]: string;
}
const url: Url = {
  login: '/login',
  register: '/register',
};

//封装接口方法
export class User {
  //登录
  static async login(data: {
    email: string;
    password: string;
  }): Promise<HttpResponse> {
    return axios(url.login, {
      method: 'post',
      responseType: 'json',
      data: data,
    });
  }
  //注册
  static async register(data: {
    email: string;
    username: string;
    password: string;
  }): Promise<HttpResponse> {
    return axios(url.register, {
      method: 'post',
      responseType: 'json',
      data: data,
    });
  }
}
